﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TouristAgencyDataLayer
{
    public class ReservationTypes
    {
        public static void CreateReservationType(string rType)
        {
            if (!string.IsNullOrEmpty(rType))
            {
                TouristAgencyDataClassesDataContext context = new TouristAgencyDataClassesDataContext();

                ReservationType m = new ReservationType()
                {
                    ReservationType1 = rType
                };

                context.ReservationTypes.InsertOnSubmit(m);
                context.SubmitChanges();
            }
        }

        public static void UpdateReservationType(int rTypeId, string rType)
        {
            if (!string.IsNullOrEmpty(rType))
            {
                TouristAgencyDataClassesDataContext context = new TouristAgencyDataClassesDataContext();

                var res =
                    (from b in context.ReservationTypes
                     where b.ReservationTypeId == rTypeId
                     select b).FirstOrDefault();

                if (res != null)
                {
                    res.ReservationType1 = rType;
                    context.SubmitChanges();
                }
            }
        }

        public static void DeleteReservationType(int rTypeId)
        {

            TouristAgencyDataClassesDataContext context = new TouristAgencyDataClassesDataContext();

            var rType =
                (from b in context.ReservationTypes
                 where b.ReservationTypeId == rTypeId
                 select b).FirstOrDefault();

            if (rType != null)
            {
                context.ReservationTypes.DeleteOnSubmit(rType);
                context.SubmitChanges();
            }
        }

        public static IQueryable<ReservationType> GetReservationTypes()
        {
            TouristAgencyDataClassesDataContext context = new TouristAgencyDataClassesDataContext();

            return context.ReservationTypes;
        }
    }
}
